<?php echo $this->element('displayHeader'); ?>
<div>
    <?php echo $ajax->form(null, 'post', array('update'=>'divReport', 'indicator' => 'indicator', 'url'=>array('action' => 'customer_reports_display'))); ?>
    <table>
        <tr>
            <td width="100px"><?php echo $form->label('Customer'); ?></td>
            <td><?php echo $form->select('customer', $customers, null, array('id' => 'selectCustomer', 'name' => 'data[customer_id]')); ?>
        </tr>
        <tr>
            <td><?php echo $form->label('Site'); ?></td>
            <td>
                <?php echo $form->select(null, null, null, array('id' => 'selectSite', 'name' => 'data[site_id]')); ?>
                <?php echo $form->submit('Go', array('class' => 'ui-state-default ui-corner-all', 'id' => 'btnSubmit')); ?>
            </td>
        </tr>
    </table>
    <?php echo $form->end(); ?>
</div>

<div id="divReport"></div>

<script type="text/javascript">
    $j(function() {
        $j('#selectCustomer').bind('change', function() {
            $j("#selectSite").requestOptions('sites/option_list', $j('#selectCustomer').val());
        });

        // ตอนแรกยังไม่ได้เลือก Site ใด ๆ disabled ปุ่มไว้ก่อน
        $j('#btnSubmit').handover().addClass('ui-state-disabled').attr('disabled', true);

        $j("#selectCustomer").bind('change', function() {
            $j('#btnSubmit').addClass('ui-state-disabled').attr('disabled', true);
            $j('#divReport').hide();
        });

        // ถ้าเลือก Site แล้ว ค่อย Submit ได้
        $j("#selectSite").bind('change', function() {
            if ($j(this).val() != '') {
                $j('#btnSubmit').removeClass('ui-state-disabled').removeAttr('disabled');
                $j('#divReport').empty().show();

            } else {
                $j('#btnSubmit').addClass('ui-state-disabled').attr('disabled', true);
                $j('#divReport').hide();
            }
        });
    });
</script>
